<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>

        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">

            <title>长约合同签署</title>

            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->

        </head>
        <style>
            input:disabled {
                background-color: #dae1ed;
            }

            a {
                text-decoration: none
            }
        </style>

        <body>
            <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            /**
                             * 初始化日期选择框
                             */
                            $('#startDraftTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endDraftTime').datebox('setValue', getNowFormatDate());
                            $('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            // 初始化长约合同签署列表
                            bindgrid()
                            // 初始化长约起草列表
                            setchDraftsDataGrid()
                            $("#uploadbtn").bind("click", function (e) {
                                $("#uploadpicker").click();
                            });
                        });

                    </script>

                    <script>
                        function del(node) {
                            if (+node.status == '1') {
                                $.messager.alert('提示', '已提交的数据无法删除')
                                return
                            }
                            $.ajax({
                                type: "delete",
                                url: 'sale/contract/sign/delete?id=' + node.sigId,
                                //                dataType: "xml",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#add').window('close');
                                    $('#dg').datagrid('enableFilter');
                                    $('#dg').datagrid('load');
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function save(action) {
                            if (!$('#fm').form('validate')) {
                                $.messager.alert('提示', '请完善必填数据')
                                return;
                            }
                            let model = {
                                draCode: $('#draCode').val(),
                                // 长约合同签署，默认为非虚拟合同
                                draVirtual: '0',
                                longTerm: $('#longTerm').val(),
                                sigId: $('#sigId').val(),
                                draId: $('#draId').val(),
                                draName: $('#draName').val(),
                                infCode: $('#infCode').val(),
                                infName: $('#infName').val(),
                                draMoney: $('#draMoney').val(),
                                draCurrency: $('#draCurrencyTrade').combobox('getValue'),
                                remark: $('#remark').val(),
                                status: '0'
                            }
                            saveAjax(model, action)
                        }

                        // 保存的ajax
                        function saveAjax(obj, action) {
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'sale/contract/sign/save',
                                data: JSON.stringify(obj),
                                contentType: "application/json",
                                complete: function (XMLHttpRequest) {
                                    if (XMLHttpRequest.responseJSON.code != 60200) {
                                        $.messager.alert('消息', XMLHttpRequest.responseJSON.msg);
                                    } else {
                                        const result = XMLHttpRequest.responseJSON.data
                                        saveAttch(result.sigId, obj, action)
                                        if ('submit' != action) {
                                            $.messager.show({
                                                title: '提示',
                                                msg: XMLHttpRequest.responseJSON.msg,
                                                timeout: 3000,
                                                showType: 'slide'
                                            });
                                            // 刷新起草列表
                                            let draftListDataGrid = $('#draftList')
                                            draftListDataGrid.datagrid('enableFilter');
                                            draftListDataGrid.datagrid('load', {
                                                status: '1',
                                                // transedSap: '0'
                                            });

                                            // 刷新列表
                                            let dg = $('#dg');
                                            dg.datagrid('enableFilter');
                                            dg.datagrid('load');
                                            $('#add').window('close');

                                            // 重新打开窗口
                                            if ('1' != result.status) {
                                                $('#tabs').tabs({
                                                    tools: [{
                                                        text: '保存',
                                                        iconCls: 'icon-save',
                                                        handler: function () {
                                                            save('save');
                                                        }
                                                    }, {
                                                        text: '提交',
                                                        iconCls: 'icon-ok',
                                                        handler: function () {
                                                            $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                                                function (r) {
                                                                    if (r) {
                                                                        save('submit')
                                                                    }
                                                                });
                                                        }
                                                    }]
                                                })
                                            } else {
                                                $('#tabs').tabs({
                                                    tools: null
                                                })
                                            }
                                            detail(result.sigId)
                                        }
                                    }
                                },
                                success: function (data) {
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        // 提交
                        function commit(obj) {
                            obj.status = '1'
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'sale/contract/sign/save',
                                data: JSON.stringify(obj),
                                contentType: "application/json",
                                success: function (data) {
                                    let dg = $('#dg');
                                    dg.datagrid('enableFilter');
                                    dg.datagrid('load');
                                    $('#add').window('close');
                                    if (data.code != 60200) {
                                        detail(obj.sigId)
                                        $.messager.alert('消息', data.msg);

                                    } else {
                                        $.messager.alert('消息', data.msg);
                                    }


                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        // 编辑合同签署
                        function editrow(row) {
                            if (+row.status == '1') {
                                $.messager.alert('提示', '已提交的数据不得再次编辑')
                                return
                            }
                            $('#tabs').tabs({
                                tools: [{
                                    text: '保存',
                                    iconCls: 'icon-save',
                                    handler: function () {
                                        save('save');
                                    }
                                }, {
                                    text: '提交',
                                    iconCls: 'icon-ok',
                                    handler: function () {
                                        $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                            function (r) {
                                                if (r) {
                                                    save('submit')
                                                }
                                            });
                                    }
                                }]
                            })
                            // 编辑时不得弹出选择框
                            $('#selectDraftWindow').window({
                                onBeforeOpen: function () {
                                    return false
                                }
                            })
                            $('#fm').form('load', row);
                            $('#draCurrencyTrade').combobox('setValue', row.draCurrency)
                            getSignInfoBySigId(row.draId)
                        }

                        // 签署详情方法
                        function detail(sigId) {
                            $.ajax({
                                type: "get",
                                dataType: "json",
                                url: 'sale/contract/sign/selectInfor?id=' + sigId,
                                success: function (data) {
                                    if (data.code != 60200) {
                                        $.messager.alert('消息', data.msg);
                                    } else {
                                        let row = data.data
                                        // 取得附件列表
                                        getFileList(row)
                                        setFormFieds(row)
                                        getSignInfoBySigId(row.draId)
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                            $('#add').window('open');
                            $('#tabs').tabs('select', 0);
                        }

                        // 根据draId取得详情的ajax
                        function getSignInfoBySigId(draId) {
                            $.ajax({
                                type: "get",
                                dataType: "json",
                                url: 'sale/contract/draft/selectInfor?id=' + draId,
                                success: function (data) {
                                    if (data.code != 60200) {
                                        $.messager.alert('消息', data.msg);
                                    } else {
                                        let row = data.data
                                        setProductDataGrid(row.productModels)
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function bindgrid() {
                            let startTime = $('#startTime').datebox('getValue')
                            let endTime = $('#endTime').datebox('getValue')
                            let status = $('#status').combobox('getValue')
                            $('#dg').datagrid(
                                {
                                    title: '',
                                    queryParams: {
                                        startTime: startTime ? startTime : '',
                                        endTime: endTime ? endTime : '',
                                        status: status,
                                        longTerm: '1'
                                    },
                                    url: "sale/contract/sign/selectList",
                                    iconCls: 'icon-application',
                                    width: getWidth(0.98),
                                    height: 400,
                                    nowrap: true,
                                    filterDelay: 0,
                                    rownumbers: true,
                                    animate: false,
                                    collapsible: false,
                                    clientPaging: false,
                                    remoteFilter: true,
                                    singleSelect: true,
                                    pagination: true,
                                    remoteSort: true,
                                    columns: [
                                        [{
                                            field: 'sigId',
                                            title: '签署id',
                                            sortable: true,
                                            hidden: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'draId',
                                            title: '合同起草id',
                                            sortable: true,
                                            hidden: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'draCode',
                                            title: '合同编号',
                                            sortable: true,
                                            formatter: function (val, rec, index) {
                                                let valTem = val ? val : '--'
                                                return "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"detail('" + rec.sigId
                                                    + "')\">" + valTem + "</a>"
                                            }
                                        },
                                        {
                                            field: 'poNumber',
                                            title: '采购订单号',
                                            sortable: true,
                                            formatter: function (val, rec, index) {
                                                let valTem = val ? val : '--'
                                                return val ? unescape(val) : '';
                                            }
                                        },
                                        {
                                            field: 'draName',
                                            title: '合同名称',
                                            sortable: true,
                                            formatter: function (val, rec, index) {
                                                return "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"detail('" + rec.sigId
                                                    + "')\">" + val + "</a>"
                                            }
                                        }, {
                                            field: 'longTerm',
                                            title: '是否长约',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val == '1' ? '是' : '否';
                                            }
                                        }, {
                                            field: 'infCode',
                                            title: '客户编码',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'infName',
                                            title: '客户名称',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'draMoney',
                                            title: '合同金额',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'draCurrency',
                                            title: '合同币种',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'createTime',
                                            title: '创建时间',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'createName',
                                            title: '创建人',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'createId',
                                            title: 'create_id',
                                            sortable: true,
                                            hidden: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'updateId',
                                            title: 'update_id',
                                            sortable: true,
                                            hidden: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'updateName',
                                            title: '更新人',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'updateTime',
                                            title: '更新时间',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'status',
                                            title: '状态',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return +unescape(val) == '1' ? '已提交' : '待提交';
                                            }
                                        }, {
                                            field: 'remark',
                                            title: '备注',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }]],
                                    toolbar: [
                                        {
                                            text: '增加',
                                            iconCls: 'icon-add',
                                            handler: function () {
                                                addContractSign()
                                            }
                                        },
                                        '-',
                                        {
                                            text: '编辑',
                                            iconCls: 'icon-edit',
                                            handler: function () {
                                                let row = $('#dg').datagrid('getSelected');
                                                if (row) {
                                                    editrow(row)
                                                } else {
                                                    $.messager.alert('提示', '请选择要编辑的数据')
                                                    return
                                                }
                                            }
                                        },
                                        '-',
                                        {
                                            text: '删除',
                                            iconCls: 'icon-cancel',
                                            handler: function () {
                                                var row = $('#dg').datagrid(
                                                    'getSelected');
                                                if (row) {
                                                    $.messager.confirm('提示',
                                                        '确定要删除这个吗?', function (r) {
                                                            if (r) {
                                                                del(row);
                                                            }
                                                        });
                                                }
                                            }
                                        }],
                                    onLoadSuccess: function () {
                                    },
                                });
                            $('#dg').datagrid('enableFilter');
                        }
                    </script>
                    <style scoped="scoped">
                        .textbox {
                            height: 20px;
                            margin: 0;
                            padding: 0 2px;
                            box-sizing: content-box;
                        }

                        /*.table tr {
            height: 15px;
        }*/
                    </style>
                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <%-- 搜索框 --%>
                                <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                    name="startTime" id="startTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                    class="easyui-datebox" name="endTime" id="endTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    style="width: 150px" /> <label
                                    style="margin-left: 20px; font-size: 12px;">状态：</label> <input
                                    class="easyui-combobox" id="status" name="status" style="width: 80px" data-options="valueField: 'value',
		textField: 'label',editable:false,panelHeight:'auto',data: [{
			label: '全部',
			value: ''
		},{
			label: '待提交',
			value: '0',
			'selected':true
		},{
			label: '已提交',
			value: '1'
		}]">
                                <%-- <option value="">
                                    </option>
                                    <option value="0">待提交</option>
                                    <option value="1">已提交</option>--%>
                                    </select> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
                                        class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                        onclick="selectSignList()">查询</a>
                        </div>
                        <table id="dg"></table>
                        <!-- 新增合同签署弹窗 -->
                        <div id="add" class="easyui-window" closed="true" modal="true" title="合同签署"
                            style="width: 900px; height: 430px; padding: 10px 20px">
                            <form id="fm" class="ssec-form">
                                <div id="tabs" class="easyui-tabs" style="width: 840px; height: 350px">
                                    <div title="基本信息" style="padding: 5px;">
                                        <table class="table">
                                            <tr>
                                                <td>
                                                    <!-- 合同编号-->
                                                    <input id="draCode" type="hidden" name="draCode"
                                                        class="easyui-validatebox textbox"
                                                        data-options="required:false" />
                                                    <!-- 签署id-->
                                                    <input id="sigId" type="hidden" name="sigId"
                                                        class="easyui-validatebox textbox"
                                                        data-options="required:false" />
                                                    <!-- 合同起草id-->
                                                    <input id="draId" type="hidden" name="draId"
                                                        class="easyui-validatebox textbox"
                                                        data-options="required:false" />
                                                    <%-- 是否长约 --%>
                                                        <input id="longTerm" type="hidden" name="longTerm"
                                                            class="easyui-validatebox textbox"
                                                            data-options="required:false" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">合同起草：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal" id="searchDiv"
                                                        onclick="searchDraftList()">
                                                        <input id="draName" name="draName" class="easyui-textbox"
                                                            data-options="prompt:'点击查询合同起草列表',required:true" />
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="ssec-label">客户编码：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="infCode" name="infCode"
                                                            class="easyui-validatebox textbox"
                                                            data-options="required:true,disabled:true" />
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="ssec-label">客户名称：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="infName" name="infName"
                                                            class="easyui-validatebox textbox"
                                                            data-options="required:true,disabled:true" />
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <div class="ssec-label">合同金额：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="draMoney" name="draMoney"
                                                            class="easyui-validatebox textbox"
                                                            data-options="required:true,disabled:true" />
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="ssec-label">合同币种：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="draCurrencyTrade" name="draCurrency"
                                                            style="width: 170px" class="easyui-combobox"
                                                            data-options="required:true,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="ssec-label">备注：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="remark" name="remark"
                                                            class="easyui-validatebox textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                                <%-- <td>
                                                    <div class="ssec-label">create_time：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="createTime" name="createTime"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>--%>
                                            </tr>
                                            <%--<tr>
                                                <td>
                                                    <div class="ssec-label">create_name：</div>
                                                </td>
                                                <td>
                                                    <div class="ssec-text normal">
                                                        <input id="createName" name="createName"
                                                            class="easyui-validatebox textbox"
                                                            data-options="required:true" />
                                                    </div>
                                                </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">create_id：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="createId" name="createId"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">update_id：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="updateId" name="updateId"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">update_name：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="updateName" name="updateName"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">update_time：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="updateTime" name="updateTime"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">del_flag：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="delFlag" name="delFlag"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">status：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="status" name="status"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>
                                                </tr>--%>
                                        </table>
                                    </div>
                                    <div title="合同产品列表" style="padding: 5px;">
                                        <table id="products"></table>
                                    </div>
                                    <div title="附件" style="padding: 5px;">
                                        <table>
                                            <tr>
                                                <td colspan="3">
                                                    <input type="button" id="uploadbtn" value="选择文件..." />
                                                    <input type="file" id="uploadpicker" accept=""
                                                        onchange="changeFile()" multiple style="display: none;" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <label style="width:40%;text-align:right;">附件下载：</label>
                                                    <ul id="checkfileList"></ul>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </form>
                        </div>

                        <div id="selectDraftWindow" class="easyui-window" closed="true" modal="true" title="合同起草列表"
                            style="width: 900px; height: 400px; padding: 5px">
                            <!-- 搜索框 -->
                            <label style="font-size:7px;">创建时间：</label>
                            <input class="easyui-datebox" id="startDraftTime"
                                data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                value="" style="width:150px">
                            <label style="font-size:10px;">~</label>
                            <input class="easyui-datebox" id="endDraftTime"
                                data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                style="width:150px" />
                            </select>
                            <a style="margin-left: 30px" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-search'" onclick="selectList()">查询</a>
                            <a style="margin-left: 5px" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-ok'" onclick="addContract()">确定</a>
                            <!--合同签署列表DataGrid  -->
                            <table id="draftList"></table>
                        </div>
                    </div>
        </body>
        <script>
            var selectedFileList = [];//已选文件列表
            var succsessCount = 0;//上传成功文件个数
            var errorCount = 0;//上传失败文件个数
            // 增加合同签署
            function addContractSign() {

                $('#tabs').tabs({
                    tools: [{
                        text: '保存',
                        iconCls: 'icon-save',
                        handler: function () {
                            save('save');
                        }
                    }, {
                        text: '提交',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                function (r) {
                                    if (r) {
                                        save('submit')
                                    }
                                });
                        }
                    }]
                })
                //
                $('#add').window({
                    onBeforeOpen: function () {
                        return true
                    }
                })
                $('#fm').form('clear');
                selectedFileList = []
                $("#checkfileList").empty()
                setProductDataGrid([])
                $('#add').window('open')
            }

            // 查询合同起草列表
            function searchDraftList() {
                $('#selectDraftWindow').window('open')
            }

            // 查询长约合同起草列表
            function setchDraftsDataGrid() {
                // 构建查询合同起草的dataGrid
                let startTime = $('#startDraftTime').datebox('getValue')
                let endTime = $('#endDraftTime').datebox('getValue')
                let draftListDataGrid = $('#draftList')
                draftListDataGrid.datagrid({
                    queryParams: {
                        startTime: startTime ? startTime : '',
                        endTime: endTime ? endTime : '',
                        status: '1',
                        longTerm: '1'
                    },
                    url: "sale/contract/draft/selectList",
                    iconCls: 'icon-application',
                    width: 860,
                    height: 310,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    clientPaging: false,
                    remoteFilter: true,
                    singleSelect: true,
                    pagination: true,
                    remoteSort: true,
                    columns: [
                        [{
                            field: 'draId',
                            title: '合同起草id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, /*{
                        field: 'temId',
                        title: '模板id',
                        sortable: true,
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'temName',
                        title: '模板名称',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, */{
                            field: 'draCode',
                            title: '合同编号',
                            sortable: true,
                            formatter: function (val, rec, index) {
                                return val ? unescape(val) : '';

                            }
                        }, {
                            field: 'draName',
                            title: '合同名称',
                            sortable: true,
                            formatter: function (val, rec, index) {
                                return val ? unescape(val) : '';

                            }
                        }, {
                            field: 'draMoney',
                            title: '合同金额',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTax',
                            title: '税率',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTransportId',
                            title: '运输方式id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTransportName',
                            title: '运输方式',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draIsIn',
                            title: '是否内贸',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSettleId',
                            title: '结算方式id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSettleName',
                            title: '结算方式',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPackageMoney',
                            title: '包装费',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTransportMoney',
                            title: '运输单价',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draDays',
                            title: '账期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPaymentId',
                            title: '付款方式id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPaymentName',
                            title: '付款方式',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'infCode',
                            title: '客商编码',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'infName',
                            title: '客商名称',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'infLegalPerson',
                            title: '客商法定代表人',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'infHandlePerson',
                            title: '客商代办人',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTypeId',
                            title: '合同类型id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTypeName',
                            title: '合同类型name',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSignTime',
                            title: '合同签订日期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draStartTime',
                            title: '合同起始日期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draEndTime',
                            title: '合同终止日期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'oaUserId',
                            title: 'oa用户id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'oaWfId',
                            title: 'oa流程id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'daCurrency',
                            title: '币种',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSeaMoney',
                            title: '海运费',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draRate',
                            title: '汇率',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draAgreementId',
                            title: '收付款协议',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draAgreementName',
                            title: '收付款协议',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'createTime',
                            title: '创建时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'createName',
                            title: '创建人',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'createId',
                            title: 'create_id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'updateId',
                            title: 'update_id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'updateName',
                            title: '更新人',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'updateTime',
                            title: '更新时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'delFlag',
                            title: 'del_flag',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'status',
                            title: '状态',
                            sortable: true,
                            formatter: function (val, rec) {
                                return +val == '1' ? unescape('已提交') : '待提交';
                            }
                        }, {
                            field: 'remark',
                            title: '备注',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }
                        ]
                    ],
                    // toolbar: [{
                    //     text: '确定',
                    //     iconCls: 'icon-ok',
                    //     handler: function () {
                    //         let row = $('#draftList').datagrid('getSelected')
                    //         if (!row) {
                    //             $.messager.alert('提示', '请选择一条数据')
                    //             return
                    //         }
                    //         getSelectedDraft(row.draId)
                    //         $('#selectDraftWindow').window('close')
                    //     }
                    // }],
                    onLoadSuccess: function () {

                    }
                }
                );
                draftListDataGrid.datagrid('enableFilter');
            }

            function addContract() {
                let row = $('#draftList').datagrid('getSelected')
                if (!row) {
                    $.messager.alert('提示', '请选择一条数据')
                    return
                }
                getSelectedDraft(row.draId)
                $('#selectDraftWindow').window('close')

            }

            // 将选中的合同起草赋值给合同签署
            function getSelectedDraft(draId) {
                $.ajax({
                    type: 'get',
                    url: 'sale/contract/draft/selectInfor?id=' + draId,
                    dataType: 'json',
                    success: function (data) {
                        if (data.code != 60200) {
                            $.messager.alert('消息', '未查询到数据');
                        } else {
                            let draft = data.data
                            console.log("1111", draft)
                            if (!draft) return
                            setFormFiedsWithDraft(draft)
                            // 产品明细
                            const productModelsArr = draft.productModels
                            // 加载产品明细datagrid
                            setProductDataGrid(productModelsArr)
                        }
                    }
                })
            }

            // 条件查询
            function selectList() {
                var startTime = $('#startTime').datebox('getValue')
                var endTime = $('#endTime').datebox('getValue')
                var status = $('#status').combobox('getValue');
                var dg = $('#dg');
                dg.datagrid('enableFilter');
                dg.datagrid('load', {
                    startTime: startTime ? startTime : '',
                    endTime: endTime ? endTime : '',
                    status: '1',
                    longTerm: '1'
                });
            }

            /***
             * 条件查询
             */
            function selectSignList() {
                let startTime = $('#startTime').datebox('getValue')
                let endTime = $('#endTime').datebox('getValue')
                let status = $('#status').combobox('getValue')
                let dg = $('#dg');
                dg.datagrid('enableFilter');
                dg.datagrid('load', {
                    startTime: startTime ? startTime : '',
                    endTime: endTime ? endTime : '',
                    status: status,
                    longTerm: '1'
                })
            }

            // 加载产品明细datagrid
            function setProductDataGrid(obj) {
                let products = $('#products')
                products.datagrid({
                    data: obj,
                    iconCls: 'icon-application',
                    clientPaging: false,
                    remoteFilter: true,
                    filterDelay: 0,
                    width: 810,
                    height: 300,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    singleSelect: true,
                    pageSize: 10,
                    remoteSort: false,
                    pagination: true,
                    columns: [
                        [{
                            field: 'draId',
                            title: '合同起草id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'sigId',
                            title: '合同签署id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'proId',
                            title: '产品Id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'lineNumber',
                            title: '产品行号',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'skuNum',
                            title: 'SKU编码',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'skuDescription',
                            title: 'SKU描述',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draCode',
                            title: '产品编码',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draName',
                            title: '产品名称',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSpecs',
                            title: '规格',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draUnit',
                            title: '计量单位',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draNum',
                            title: '数量',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPriceList',
                            title: '价目表名称',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draUnitPrice',
                            title: '原币含税单价',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draWaterPrice',
                            title: '净水价',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draBasicPrice',
                            title: '基准价',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draDiffer',
                            title: '与基准价差额',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draDifferRadio',
                            title: '差额比例',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draMixPrice',
                            title: '运杂费',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'draTax',
                            title: '税率',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'draTaxNum',
                            title: '税码',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'draTotalPrice',
                            title: '原币价税合计',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draExeUnitPrice',
                            title: '原币无税单价',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draCommission',
                            title: '佣金',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPackageId',
                            title: '包装方式Id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPackageName',
                            title: '包装方式',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'draPackageNum',
                            title: '包装数量',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'draPackExpense',
                            title: '包装费',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'remark',
                            title: '备注',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'purchaseAmount',
                            title: '采购数量',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'purchasePrice',
                            title: '采购单价',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'transportPrice',
                            title: '运输单价',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'planArrivalDate',
                            title: '计划日期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'arrivalFactory',
                            title: '到货工厂',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        },
                        {
                            field: 'repertoryAddress',
                            title: '库存地点',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }]],
                    onLoadSuccess: function () {

                    },
                })

            }

            // 新增、编辑、详情表单字段赋值
            function setFormFieds(model) {
                if (+model.status != '1') {
                    $('#tabs').tabs({
                        tools: [{
                            text: '保存',
                            iconCls: 'icon-save',
                            handler: function () {
                                save('save');
                            }
                        }, {
                            text: '提交',
                            iconCls: 'icon-ok',
                            handler: function () {
                                $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                    function (r) {
                                        if (r) {
                                            save('submit')
                                        }
                                    });
                            }
                        }]
                    })
                }
                $('#fm').form('load', model);
                $('#draCurrencyTrade').combobox('setValue', model.draCurrency)
            }

            function setFormFiedsWithDraft(model) {
                if (+model.status != '1') {
                    $('#tabs').tabs({
                        tools: [{
                            text: '保存',
                            iconCls: 'icon-save',
                            handler: function () {
                                save('save');
                            }
                        }, {
                            text: '提交',
                            iconCls: 'icon-ok',
                            handler: function () {
                                $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                    function (r) {
                                        if (r) {
                                            save('submit')
                                        }
                                    });
                            }
                        }]
                    })
                }
                $('#fm').form('load', model);
                $('#longTerm').val(model.longTerm)
                $('#draCurrencyTrade').combobox('setValue', model.daCurrency)
            }

            /************文件处理部分*************/

            /**
             * 保存附件
             */
            function saveAttch(row, obj, action) {
                obj.sigId = row
                let saveNum = 0
                if (selectedFileList.length > 0) {
                    $.each(selectedFileList, function (index, item) {
                        var dataform = new FormData();
                        dataform.append("file", item);
                        var xmlhttp = null;
                        if (window.XMLHttpRequest) { // code for all new browsers
                            xmlhttp = new XMLHttpRequest();
                        } else if (window.ActiveXObject) {// code for IE5 and IE6
                            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        if (xmlhttp != null) {
                            xmlhttp.open("POST", "api/file/springUpload?fileRow=" + row
                                + "&fileTable=sale_contract_sign&fileName="
                                + item.name, true);
                            xmlhttp.setRequestHeader('token', localStorage.getItem('token'));
                            xmlhttp.setRequestHeader('userType', localStorage.getItem('userType'));
                            xmlhttp.send(dataform);
                            xmlhttp.onreadystatechange = callbackMethods;
                        } else {
                            alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                        }

                        function callbackMethods() {
                            if (xmlhttp.readyState == 4) {
                                if (xmlhttp.status == 200) {
                                    saveNum += 1
                                }
                                if (saveNum == selectedFileList.length) {
                                    disLoad();
                                    if ('submit' == action) {
                                        commit(obj)

                                    }
                                }
                            } else {
                                if (xmlhttp.status == 500) {
                                }
                            }
                        }
                    });

                } else {
                    if ('submit' == action) {
                        commit(obj)
                    }
                }
            }

            /**
             *文件框改变事件
             */
            function changeFile() {
                var files = $("#uploadpicker").prop("files");
                $.each(
                    files,
                    function (index, item) {
                        let choiseFile = $("#checkfileList>li");
                        if (choiseFile.length > 0) {//文件去重
                            let count = 0;
                            $.each(choiseFile, function (index1, item1) {
                                if (item.name == item1.innerText) {
                                    count++;
                                }
                            });
                            if (count == 0) {
                                if (checkFileLength(item.size)) {
                                    if (item.name.includes('&') || item.name.includes(' ')) {
                                        alert('文件名不能包含&、空格等特殊字符！');
                                        return;
                                    }
                                    $("#checkfileList")
                                        .append(
                                            "<li class=\"fileinfo\">"
                                            + item.name
                                            + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                            + item.name
                                            + "')\">删除</a>"
                                            + "</li>");
                                    selectedFileList.push(item);
                                    AddMoushover();
                                }
                            }
                        } else {
                            if (checkFileLength(item.size)) {
                                if (item.name.includes('&') || item.name.includes(' ')) {
                                    alert('文件名不能包含&、空格等特殊字符！');
                                    return;
                                }
                                $("#checkfileList")
                                    .append(
                                        "<li class=\"fileinfo\">"
                                        + item.name
                                        + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                        + item.name
                                        + "')\">删除</a>"
                                        + "</li>");
                                selectedFileList.push(item);
                                // 										sselectedFileNameList.push(item.name);
                                AddMoushover();
                            }
                        }
                    });
            }

            /**
             *    判断文件是否超过限制大小
             * @param fileLen
             * @returns {boolean}
             */
            function checkFileLength(fileLen) {
                if (fileLen > 102400000) {
                    $.messager.alert("提示", "上传文件大小不能超过100M", "error");
                    return false;
                }
                return true;
            }

            /**
             * //添加鼠标经过事件，鼠标划过时显示“删除”
             * @constructor
             */
            function AddMoushover() {
                $(".fileinfo").hover(function () {
                    $(this).find("a").last().css("display", "");
                }, function () {
                    $(this).find("a").last().css("display", "none");
                });
            }

            /**
             *  移除已选择的文件
             */

            function RemoveFile(obj, fileId) {

                $.messager.confirm("提示", "确认删除当前文件?", function (e) {
                    if (e) {
                        let index = $("#checkfileList>li").index($(obj).parent());
                        selectedFileList.splice(index, 1);
                        $(obj).parent().remove();
                        // 					var index1 = $.inArray(filename, sselectedFileNameList);
                        // 					sselectedFileNameList.splice(index1, 1);
                        $.ajax({
                            type: "post",
                            url: 'file/deleteFile?fileId=' + fileId,
                            success: function (data) {
                                $.messager.alert('消息', data);
                            },
                            error: function (XMLHttpRequest, textStatus,
                                errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }
                        });
                    }
                })
            }

            /**
             * 取得该条数据所属的文件列表
             * @param row
             */
            function getFileList(row) {
                $.ajax({
                    type: "post",
                    url: "file/getFileList",
                    data: {
                        fileTable: "sale_contract_sign",
                        fileRow: row.sigId
                    },
                    success: function (data) {
                        const dataArray = eval(data);
                        initFile(dataArray, row.status);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            /**
             * 初始化该条数据的文件列表
             * @param dataArray
             */
            function initFile(dataArray, status) {
                $("#checkfileList").empty();
                selectedFileList = [];
                dataArray
                    .forEach(function (e, i, a) {
                        $("#checkfileList")
                            .append(
                                "<li class=\"fileinfo\">"
                                + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                + e.FILE_ID
                                + "')\">"
                                + e.FILE_NAME
                                + "</a>"
                                + (status > 0 ? '' : "</a>"
                                    + "<a style=\"display: none; color: red; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                    + e.FILE_NAME + "')\">删除</a>")
                                + "</li>");
                        // 						sselectedFileNameList.push(e.FILE_NAME);
                        if (status > 0) {
                        } else {
                            AddMoushover();
                        }
                    });
            }

            function downloadFile(fileName, fileRow) {
                let url = 'api/file/download?id=' + fileRow
                let xhr = new XMLHttpRequest()
                xhr.open('GET', url, true)
                xhr.setRequestHeader('token', localStorage.getItem('token'));
                xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                xhr.responseType = 'blob'
                xhr.onload = function (data) {
                    if (this.status == 200) {
                        let blob = this.response
                        let reader = new FileReader()
                        reader.readAsDataURL(blob)
                        reader.onload = function (e) {
                            let a = document.createElement('a')
                            a.download = fileName
                            a.href = e.target.result
                            $('body').append(a)
                            a.click()
                            $(a).remove()
                        }
                    } else {
                    }
                }
                xhr.send()
            }
        </script>

        </html>